package hot100;

public class isPalindrome2 {
    public boolean isPalindrome(mergeKLists.ListNode head) {

        mergeKLists.ListNode slow = head;
        mergeKLists.ListNode fast = head;
        //slow -> 1/2
        while(fast != null && fast.next != null) {
            fast = fast.next.next;
            slow = slow.next;
        }
        //反转 slow -> end
        mergeKLists.ListNode cur = slow.next;
        mergeKLists.ListNode curN = null;
        slow.next = null;
        while(cur != null) {
            curN = cur.next;
            cur.next = slow;
            slow = cur;
            cur = curN;
        }
        //比较
        while(slow != null){
            if(slow.val != head.val) {
                return false;
            }
            slow = slow.next;
            head = head.next;
        }
        return true;
    }
}
